package com.lixin.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitFanoutConfig {

    // 创建fanout模式交换机
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(
                "fanout_order_exchange", // 交换机名称
                false, // 交换机是否持久化
                true // 是否自动删除交换机
        );
    }

    // 创建短信消息队列
    @Bean
    public Queue smsQueue() {
        return new Queue(
                "sms.fanout.queue", // 队列名称
                false // 是否持久化
        );
    }

    // 创建微信消息队列
    @Bean
    public Queue wechatQueue() {
        return new Queue("wechat.fanout.queue", false);
    }

    // 创建邮件消息队列
    @Bean
    public Queue emailQueue() {
        return new Queue("email.fanout.queue", false);
    }

    // 将短信消息队列绑定到交换机
    @Bean
    public Binding smsBinding() {
        return BindingBuilder.bind(smsQueue()).to(fanoutExchange());
    }

    // 将微信消息队列绑定到交换机
    @Bean
    public Binding wechatBinding() {
        return BindingBuilder.bind(wechatQueue()).to(fanoutExchange());
    }

    // 将邮件消息队列绑定到交换机
    @Bean
    public Binding emailBinding() {
        return BindingBuilder.bind(emailQueue()).to(fanoutExchange());
    }

}
